//
//  News_ViewController.m
//  MagicBox
//
//  Created by dllo on 16/8/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "News_ViewController.h"
#import "MapViewController.h"
#import "PublishViewController.h"
#import "PictureViewController.h"

#define APIkey  @"3ab6b634cad13a6304c47d72161c4503"

@interface News_ViewController ()
{
    
    UIButton *_buttonHui;//定位按钮
    
}

@property (nonatomic ,strong) PictureViewController *myVC;
@property(nonatomic,strong)NSMutableArray *itemsSectionPictureArray;
@property (nonatomic, strong) CLGeocoder *geoC;//地理编码
@property(nonatomic, strong)MAMapView *mapView;//地图对象

@end

@implementation News_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NSNAction:) name:@"chuanzhi" object:nil];
    self.navigationItem.title = @"地图";
    [AMapServices sharedServices].apiKey = APIkey;
    ///初始化地图
    _mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
    
    ///把地图添加至view
    [self.view addSubview:self.mapView];
    self.mapView.showsUserLocation = YES;    //YES 为打开定位，NO为关闭定位
    
    [self initHuiButton];

    
}
//创建定位按钮
-(void)initHuiButton{
    _buttonHui = [UIButton buttonWithType:UIButtonTypeCustom];
    _buttonHui.frame = CGRectMake(20, _mapView.frame.size.height-95, 30, 30);
    _buttonHui.backgroundColor = [UIColor whiteColor];
    _buttonHui.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin;
    _buttonHui.layer.cornerRadius = 5;
    [_buttonHui addTarget:self action:@selector(buttonHui:) forControlEvents:UIControlEventTouchUpInside];
    [_buttonHui setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    [_mapView addSubview:_buttonHui];
}
//定位按钮点击方法
-(void)buttonHui:(UIButton *)button{
    //定位模式 : 追中模式
    if (_mapView.userTrackingMode != MAUserTrackingModeFollow) {
        [_mapView setUserTrackingMode:MAUserTrackingModeFollow animated:YES];
        
               //恢复缩放比例和角度
        [_mapView setZoomLevel:18 animated:YES];
        [_mapView setRotationDegree:0 animated:YES duration:0.5];
        [_mapView setCameraDegree:0 animated:YES duration:0.5];
        _mapView.userTrackingMode = MAUserTrackingModeFollowWithHeading;

        
    }
}
//定位按钮点击状态改变
-(void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
    //没有定位模式
    if (mode == MAUserTrackingModeNone) {
        [_buttonHui setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    }else{
        //开启定位
        [_buttonHui setImage:[UIImage imageNamed:@"2"] forState:UIControlStateNormal];
    }
}








- (void)NSNAction:(NSNotificationCenter *)nsn {
    
    
    
}

- (void)viewWillAppear:(BOOL)animated {
    
   // self.navigationItem.title = @"朋友圈";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"导航定位" style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction)];
    // 隐藏
    self.tabBarController.tabBar.hidden = NO;
     self.navigationController.navigationBar.hidden = NO;
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"写说说" style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction)];
  }
- (void)rightButtonAction {
    
    MapViewController *mapVC = [[MapViewController alloc] init];
    [self.navigationController pushViewController:mapVC animated:YES];
    
}

- (void)leftButtonAction {
    
    PublishViewController *PublishVC = [[PublishViewController alloc] init];
    [self.navigationController pushViewController:PublishVC animated:YES];
    
}











@end
